
<template>
  <div id="app" class="app">
    <transition name="transitionRouter">
      <router-view />
    </transition>
  </div>
</template>
<script>
export default {
  name: "App",
  beforeCreate() {},
  created() {
    //初始化服务端连接配置
    this.$store.dispatch("initUrl");
    //初始化文件保存服务端-文件保存地址配置
    this.$store.dispatch("initFiles");

    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("store")) {
      this.$store.replaceState(
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(sessionStorage.getItem("store"))
        )
      );
    }

    // 在页面刷新时将vuex里的信息保存到sessionStorage里
    // beforeunload事件在页面刷新时先触发
    window.addEventListener("beforeunload", () => {
      sessionStorage.setItem("store", JSON.stringify(this.$store.state));
    });
  },
  mounted() {
  },
  methods: {
  }
};
</script>
<style lang="scss">
* {
  padding: 0;
  margin: 0;
}
// 转场动画
.transitionRouter-enter-active,
.transitionRouter-leave-active {
  transition: opacity 1s;
}
.transitionRouter-enter,
.transitionRouter-leave-to {
  opacity: 0;
}
.app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>
